package com.pearadmin.shop.service.impl;

import java.util.List;
import java.util.ArrayList;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pearadmin.common.web.domain.request.PageDomain;
import com.pearadmin.shop.mapper.ShopGoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import com.pearadmin.shop.mapper.ShopComboMapper;
import com.pearadmin.shop.domain.ShopCombo;
import com.pearadmin.shop.service.IShopComboService;

/**
 * 店铺套餐Service业务层处理
 * 
 * @author syl
 * @date 2021-05-06
 */
@Service
public class ShopComboServiceImpl implements IShopComboService 
{
    @Autowired
    private ShopComboMapper shopComboMapper;

    @Autowired
    private ShopGoodsMapper shopGoodsMapper;

    /**
     * 查询店铺套餐
     * 
     * @param id 店铺套餐ID
     * @return 店铺套餐
     */
    @Override
    public ShopCombo selectShopComboById(Long id)
    {
        return shopComboMapper.selectShopComboById(id);
    }

    /**
     * 查询店铺套餐列表
     * 
     * @param shopCombo 店铺套餐
     * @return 店铺套餐
     */
    @Override
    public List<ShopCombo> selectShopComboList(ShopCombo shopCombo)
    {
        return shopComboMapper.selectShopComboList(shopCombo);
    }

    /**
     * 查询店铺套餐
     * @param shopCombo 店铺套餐
     * @param pageDomain
     * @return 店铺套餐 分页集合
     * */
    @Override
    public PageInfo<ShopCombo> selectShopComboPage(ShopCombo shopCombo, PageDomain pageDomain)
    {
        PageHelper.startPage(pageDomain.getPage(),pageDomain.getLimit());
        List<ShopCombo> data = shopComboMapper.selectShopComboList(shopCombo);
        for (ShopCombo combo: data) {
            combo.setGoodsId(shopGoodsMapper.selectShopGoodsById(Long.parseLong(combo.getGoodsId())).getName());
        }
        return new PageInfo<>(data);
    }

    /**
     * 新增店铺套餐
     * 
     * @param shopCombo 店铺套餐
     * @return 结果
     */

    @Override
    public int insertShopCombo(ShopCombo shopCombo)
    {
        return shopComboMapper.insertShopCombo(shopCombo);
    }

    /**
     * 修改店铺套餐
     * 
     * @param shopCombo 店铺套餐
     * @return 结果
     */
    @Override
    public int updateShopCombo(ShopCombo shopCombo)
    {
        return shopComboMapper.updateShopCombo(shopCombo);
    }

    /**
     * 删除店铺套餐对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteShopComboByIds(String[] ids)
    {
        return shopComboMapper.deleteShopComboByIds(ids);
    }

    /**
     * 删除店铺套餐信息
     * 
     * @param id 店铺套餐ID
     * @return 结果
     */
    @Override
    public int deleteShopComboById(Long id)
    {
        return shopComboMapper.deleteShopComboById(id);
    }
}
